package com.justspeak;


import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class BookSelectListActivity extends Activity {
	
	//课程选择listView组件
	private ListView listView;
	
	   /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.book_select_list);
        listView = (ListView) findViewById(R.id.book_select_list);
        
        ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
        
        for(int i=0;i<10;i++)  
        {  
            HashMap<String, Object> map = new HashMap<String, Object>();  
            map.put("ItemImage", R.drawable.title_page);//图像资源的ID  
            map.put("ItemTitle", "Oral breakthrough ");  
            map.put("ItemText", "The "+i+" series");  
            listItem.add(map);  
        }  
        
        //生成适配器的Item和动态数组对应的元素  
        SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源   
            R.layout.book_select_list_items,//ListItem的XML实现  
            //动态数组与ImageItem对应的子项          
            new String[] {"ItemImage","ItemTitle", "ItemText"},   
            //ImageItem的XML文件里面的一个ImageView,两个TextView ID  
            new int[] {R.id.ItemImage,R.id.ItemTitle,R.id.ItemText}  
        );  
        
        //添加长按点击  
        listView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {  
              
            public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {  
                menu.setHeaderTitle("长按菜单-ContextMenu");     
                menu.add(0, 0, 0, "弹出长按菜单0");  
                menu.add(0, 1, 0, "弹出长按菜单1");     
            }  
        }); 
        
        //点击课程时，开始播放
        listView.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				BookSelectListActivity.this.startActivity(new Intent(BookSelectListActivity.this,
                           LearningActivity.class));
			}
		});
        
        //添加并且显示  
        listView.setAdapter(listItemAdapter);  
          
    }
    
	/**
	 * 监听类  跳转到课程选择页面
	 * @author admin
	 *
	
	class BookListener implements OnClickListener {
		public void onClick(View v) {
			Intent intent = new Intent();
			intent.setClass(LoginActivity.this, BookSelectListActivity.class);
			LoginActivity.this.startActivity(intent);

		}
	} */
}
